package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.example.demo.entity.User;
@RestController //@Controller+@ResponseBody
public class MovieController {
	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private LoadBalancerClient balancerClient;
	@GetMapping("/movie/{id}") //@RequestMapping(method={GET})
	public User getMovieUser(@PathVariable Long id) {
		// VIP： virtual IP 
		return restTemplate.getForObject("http://microservice-provider-user/getUser/" + id, User.class);
	}
	@GetMapping("/test")
	public String testMyConfiguration() {
		ServiceInstance choose = balancerClient.choose("microservice-provider-user");
		System.out.println("吕布" + choose.getPort());
		return "1";
	}
	
	@GetMapping("/test2")
	public String testNotMyConfiguration() {
		ServiceInstance choose1 = balancerClient.choose("microservice-provider-user2");
		System.out.println("貂蝉" + choose1.getPort());
		return "2";
	}
}
